<template>
  <el-dialog
    title="提示"
    :visible.sync="dialogVisible"
    width="30%"
    :before-close="close"
     :close-on-click-modal="false"
  >
    <el-form :inline="true" ref="form" :model="form">
      <el-form-item label="商品类型名称：" prop="className">
        <el-input v-model="form.className" placeholder="请输入"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { editGoodType, addGoodType } from '@/api/gdInfo'
export default {
  name: 'Dkd3AddClass',
  // props: ['dialogInfo'],
  props: {
    dialogInfo: {
      type: Object,
      default: () => ({})
    }
  },
  data () {
    return {
      dialogVisible: false,
      form: {}
    }
  },

  mounted () {},
  watch: {
    dialogVisible (val) {
      if (val) {
        this.form = { ...this.dialogInfo }
      }
    }
  },
  methods: {
    async submit () {
      await this.$refs.form.validate()
      if (this.dialogInfo.className) {
        await editGoodType(this.form)
      } else {
        await addGoodType(this.form)
      }
      this.$emit('flash')
      this.close()
    },
    /* setForm () {
      this.form = { ...this.dialogInfo }
    }, */
    close () {
      this.dialogVisible = false
      this.form = {}
    }
  }
}
</script>

<style lang="less" scoped>
/deep/.el-dialog__footer {
  text-align: center;
}
/deep/.el-form-item__content {
  width: 400px;
  .el-input__inner {
    width: 100%;
  }
}
</style>
